package cn.com.pc.content.dto;

import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.domain.abuse.AbuseReport;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

@Data
@ToString
public class AbuseReportDTO {
    private Long id;
    private ContentType contentType;
    private Long contentId;
    private String reasons;
    private Long passportId;
    private String contact;
    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createdAt;

    public static AbuseReportDTO from(AbuseReport abuseReport) {
        AbuseReportDTO abuseReportDTO = new AbuseReportDTO();
        BeanUtils.copyProperties(abuseReport, abuseReportDTO);
        return abuseReportDTO;
    }

    public AbuseReport to() {
        AbuseReport abuseReport = new AbuseReport();
        BeanUtils.copyProperties(abuseReport, this);
        return abuseReport;
    }
}
